﻿package baseEngine.basic
{
    import __AS3__.vec.*;
    import baseEngine.collisions.*;
    import baseEngine.core.*;
    import baseEngine.materials.*;
    import baseEngine.system.*;
    import com.gengine.debug.*;
    import flash.display.*;
    import flash.display3D.*;
    import flash.display3D.textures.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.ui.*;
    import flash.utils.*;
    import frEngine.*;
    import frEngine.core.*;
    import frEngine.effectEditTool.manager.*;
    import frEngine.event.*;
    import frEngine.manager.*;
    import frEngine.math.*;
    import frEngine.postProcess.*;
    import frEngine.render.layer.*;
    import frEngine.shader.*;
    import frEngine.shader.filters.vertexFilters.*;

    public class Scene3D extends Pivot3D
    {
        public var defaultSunLight:DefaultSunLight;
        public var version:String = "1.0.0.0";
        private const _viewQuaternionTransform:Vector.<Vector3D>;
        private var _temp:Vector3D;
        private var _container:DisplayObjectContainer;
        private var _profile:String;
        private var _stageIndex:int;
        private var _paused:Boolean;
        private var _camera:Camera3D;
        public var context:Context3D;
        private var _stage3D:Stage3D;
        private var _viewPort:Rectangle;
        protected var _antialias:int = 2;
        private var _showMenu:Boolean = true;
        private var _autoResize:Boolean = false;
        protected var _clipped:Boolean = false;
        private var _updateIndex:int;
        private var _interactive:MouseCollision;
        private var _enableUpdateAndRender:Boolean = true;
        public var textureOffsetX:int = 0;
        public var textureOffsetY:int = 0;
        public var staticRect:Rectangle;
        private var _writeToTexture:Boolean = false;
        public var firstDrawFun:Function;
        public var clearColor:Vector3D;
        public var renderLayerList:RenderList;
        public var materials:Vector.<Material3D>;
        public var surfaces:Vector.<FrSurface3D>;
        public var textures:Vector.<Texture3D>;
        private var _targetMaterial:Material3D;
        public var targetFilters:Vector.<Material3D>;
        private var _currTime:Number;
        private var _time:Number;
        private var _tick:Number;
        private var _updated:Boolean;
        private var _startTime:Number;
        private var _frameRate:Number;
        public var ignoreInvisibleUnderMouse:Boolean = true;
        private var _fist:Object;
        private var _mouseEnabled:Boolean = false;
        private var _info:CollisionInfo;
        private var _last:CollisionInfo;
        private var _down:Mesh3D;
        private var _stage:Stage;
        protected var _curSelectObjects:Dictionary;
        public var selectIsEmpty:Boolean = true;
        public var postProcess:PostProcess;
        public var gameControler:Game3DControler;
        private var _sceneScale:Number = 1;
        public var cpos:Vector.<Number>;
        public static const RENDER_EVENT:String = "render";
        public static const PAUSED_EVENT:String = "paused";
        public static const POSTRENDER_EVENT:String = "postRender";
        public static const COMPLETE_EVENT:String = "complete";
        public static const PROGRESS_EVENT:String = "progress";
        public static const SORT_NONE:int = 0;
        public static const SORT_FRONT_TO_BACK:int = 1;
        public static const SORT_BACK_TO_FRONT:int = 2;
        private static var _stages3d:int;
        public static const textureWidth:int = 2048;
        public static const textureHeight:int = 1024;
        private static const transformFilter:TransformFilter = new TransformFilter();

        public function Scene3D(param1:DisplayObjectContainer)
        {
            this._viewQuaternionTransform = this.Vector.<Vector3D>([new Vector3D(0, 0, 0, 1), new Vector3D(0, 0, 0, 1), new Vector3D(1, 1, 1, 1)]);
            this._temp = new Vector3D();
            this.staticRect = new Rectangle(0, 0, textureWidth, textureHeight);
            this.renderLayerList = new RenderList();
            this._curSelectObjects = new Dictionary(false);
            this.cpos = new Vector.<Number>([1, 1, 1, 1]);
            this._interactive = new MouseCollision();
            this.clearColor = new Vector3D(0.25, 0.25, 0.25, 1);
            this.materials = new Vector.<Material3D>;
            this.surfaces = new Vector.<FrSurface3D>;
            this.textures = new Vector.<Texture3D>;
            this.targetFilters = new Vector.<Material3D>;
            this._last = new CollisionInfo();
            super("Scene");
            this.profile = Global3D.profile;
            this.camera = new PerspectiveCamera3D("Default_Scene_Camera");
            Global3D.scene = this;
            this.postProcess = PostProcess.instance;
            this.postProcess.init(this);
            this.frameRate = 45;
            this._container = param1;
            this.defaultSunLight = new DefaultSunLight();
            this.gameControler = new Game3DControler();
            this.addChild(this.gameControler);
            if (this._container.stage)
            {
                this.addedToStageEvent();
            }
            else
            {
                this._container.addEventListener(Event.ADDED_TO_STAGE, this.addedToStageEvent, false, 0, true);
            }
            return;
        }// end function

        public function get writeToTexture() : Boolean
        {
            return this._writeToTexture;
        }// end function

        public function addSelectObject(param1:Mesh3D, param2:Boolean, param3:Number = 15335424) : void
        {
            var _loc_4:UseOriTexShaderbase = null;
            if (param1 && param1.layer != Layer3DManager.warpLayer)
            {
                _loc_4 = UseOriTexShaderbase.getInstanceFromPool("secondMbone3", true, transformFilter, null);
                _loc_4.materialParams.skinNum = 3;
                _loc_4.materialParams.setRimBaseColor(param3, true);
                this._curSelectObjects[param1] = _loc_4;
                param1.changeToAdditionalMaterial(_loc_4);
                this.selectIsEmpty = false;
            }
            return;
        }// end function

        public function removeSelectObject(param1:Mesh3D, param2:Boolean) : void
        {
            var _loc_3:Object = null;
            var _loc_4:Number = NaN;
            var _loc_5:UseOriTexShaderbase = null;
            if (param1)
            {
                _loc_3 = this._curSelectObjects[param1];
                delete this._curSelectObjects[param1];
                if (!_loc_3)
                {
                    return;
                }
                if (_loc_3 is UseOriTexShaderbase)
                {
                    _loc_5 = UseOriTexShaderbase(_loc_3);
                    UseOriTexShaderbase.disposeInstance(_loc_5, false);
                    param1.removeAdditionalMaterial(_loc_5);
                }
                this.selectIsEmpty = true;
                for each (_loc_4 in this._curSelectObjects)
                {
                    
                    this.selectIsEmpty = false;
                    break;
                }
            }
            return;
        }// end function

        public function get selectObjects() : Vector.<Mesh3D>
        {
            var _loc_2:Object = null;
            var _loc_1:* = new Vector.<Mesh3D>;
            for (_loc_2 in this._curSelectObjects)
            {
                
                _loc_1.push(Mesh3D(_loc_2));
            }
            return _loc_1;
        }// end function

        public function get container() : DisplayObjectContainer
        {
            return this._container;
        }// end function

        override public function dispose(param1:Boolean = true) : void
        {
            this.freeMemory();
            super.dispose(param1);
            if (Global3D.scene == this)
            {
                Global3D.scene = null;
            }
            if (Global3D.camera == this.camera)
            {
                Global3D.camera = null;
            }
            this.camera = null;
            if (this.stage)
            {
                this.autoResize = false;
                this._stage = null;
            }
            if (this._showMenu)
            {
                this._container.contextMenu = null;
            }
            this._container.removeEventListener(Event.ENTER_FRAME, this.enterFrameEvent);
            this._container.removeEventListener(Event.ADDED_TO_STAGE, this.addedToStageEvent);
            this._container = null;
            this._stage3D.removeEventListener(Event.CONTEXT3D_CREATE, this.stageContextEvent);
            this._stage3D = null;
            if (this.context)
            {
                this.context.clear(this.clearColor.x, this.clearColor.y, this.clearColor.z);
            }
            this._info = null;
            this._last = null;
            this._down = null;
            this._interactive.dispose();
            this._interactive = null;
            this._container = null;
            this._viewPort = null;
            this._fist = null;
            _stages3d = _stages3d - (1 << this._stageIndex);
            Mouse.cursor = MouseCursor.AUTO;
            return;
        }// end function

        public function get stage() : Stage
        {
            if (this._stage)
            {
                return this._stage;
            }
            if (this._container)
            {
                return this._container.stage;
            }
            return null;
        }// end function

        private function addedToStageEvent(event:Event = null) : void
        {
            var e:* = event;
            this._stage = this._container.stage;
            this._container.removeEventListener(Event.ADDED_TO_STAGE, this.addedToStageEvent);
            if (_stages3d == 0)
            {
                Input3D.initialize(this.stage);
            }
            Input3D.stage = this.stage;
            this._container.addEventListener(Event.REMOVED_FROM_STAGE, this.removedFromStageEvent, false, 0, true);
            this._stageIndex = -1;
            if ((_stages3d & 1) == 0)
            {
                this._stageIndex = 0;
            }
            else if ((_stages3d & 2) == 0)
            {
                this._stageIndex = 1;
            }
            else if ((_stages3d & 4) == 0)
            {
                this._stageIndex = 2;
            }
            else if ((_stages3d & 8) == 0)
            {
                this._stageIndex = 3;
            }
            if (this._stageIndex >= 0)
            {
                _stages3d = _stages3d | 1 << this._stageIndex;
            }
            else
            {
                throw new Error("No more Stage3D\'s availables.");
            }
            this._stage3D = this.stage.stage3Ds[this._stageIndex];
            if (this._stage3D.context3D)
            {
                this.stageContextEvent(new Event(Event.CONTEXT3D_CREATE));
            }
            else
            {
                this._stage3D.addEventListener(Event.CONTEXT3D_CREATE, this.stageContextEvent, false, 0, true);
                try
                {
                    this._stage3D.requestContext3D.call(this, Context3DRenderMode.AUTO, this.profile);
                }
                catch (e:ErrorEvent)
                {
                    _stage3D.requestContext3D(Context3DRenderMode.AUTO);
                }
            }
            this.autoResize = this._autoResize;
            return;
        }// end function

        public function reUploadHander(param1:Boolean) : void
        {
            return;
        }// end function

        private function removedFromStageEvent(event:Event) : void
        {
            FrEventDispatcher.instance.proxyRemoveEventListener(this, Event.REMOVED_FROM_STAGE, this.removedFromStageEvent);
            if (this._stage)
            {
                this._stage = null;
            }
            return;
        }// end function

        private function stageContextEvent(event:Event) : void
        {
            var e:* = event;
            Log.debugMsg(LogType.other, "create context3d !");
            if (this._showMenu && this._container && this.context == null)
            {
                try
                {
                    if (!this._container.contextMenu)
                    {
                        this._container.contextMenu = new ContextMenu();
                    }
                    DisplayObjectContainer(this._container.root).contextMenu["customItems"].push(new ContextMenuItem("Flash3D " + this.version));
                }
                catch (e:Error)
                {
                }
            }
            if (this.context && this.context != this._stage3D.context3D)
            {
                this.context.dispose();
            }
            this.context = this._stage3D.context3D;
            if (!this.context)
            {
                throw new Error("context 出错了 ！");
            }
            if (this.profile == Context3DProfile.BASELINE_CONSTRAINED && this.context.driverInfo.indexOf("software") != -1)
            {
                this.profile = Context3DProfile.BASELINE;
                try
                {
                    this._stage3D.requestContext3D.call(this, Context3DRenderMode.AUTO, this.profile);
                }
                catch (e:ErrorEvent)
                {
                    this.profile = Context3DProfile.BASELINE;
                    _stage3D.requestContext3D(Context3DRenderMode.AUTO);
                }
                return;
            }
            Global3D.setDiverType(this.context.driverInfo);
            if (!this._viewPort)
            {
                this.setViewport(0, 0, this.stage.stageWidth, this.stage.stageHeight, this._antialias);
            }
            else
            {
                this._stage3D.x = this._viewPort.x;
                this._stage3D.y = this._viewPort.y;
                this.context.configureBackBuffer(this._viewPort.width, this._viewPort.height, this._antialias, true);
            }
            if (this._enableUpdateAndRender)
            {
                this._container.addEventListener(Event.ENTER_FRAME, this.enterFrameEvent);
            }
            var _loc_3:* = Global3D;
            var _loc_4:* = Global3D.configNum + 1;
            _loc_3.configNum = _loc_4;
            if (Global3D.configNum == 1)
            {
                this.defaultSunLight.init();
                Device3D.uploadGlobleParams(this.context);
                this.postProcess.immediatelyToUpload(this);
            }
            else
            {
                Resource3dManager.instance.reUpload();
                if (!this.context)
                {
                    return;
                }
                Program3dManager.instance.reUpload(this.context);
                this.defaultSunLight.reinit(this.context);
                Device3D.uploadGlobleParams(this.context);
                this.postProcess.reUpload(this);
            }
            FrEventDispatcher.instance.proxyDispatchEvent(this, e.type);
            return;
        }// end function

        public function set backgroundColor(param1:int) : void
        {
            this.clearColor.z = (param1 & 255) / 255;
            this.clearColor.y = (param1 >> 8 & 255) / 255;
            this.clearColor.x = (param1 >> 16 & 255) / 255;
            return;
        }// end function

        public function get backgroundColor() : int
        {
            return int(this.clearColor.x * 255) << 16 | int(this.clearColor.y * 255) << 8 | int(this.clearColor.z * 255);
        }// end function

        public function setViewport(param1:Number = 0, param2:Number = 0, param3:Number = 640, param4:Number = 480, param5:int = 0) : void
        {
            if (param3 < 50)
            {
                param3 = 50;
            }
            if (param4 < 50)
            {
                param4 = 50;
            }
            if (this.context && this.context.driverInfo.indexOf("Software") != -1)
            {
                if (param3 > 2048)
                {
                    param3 = 2048;
                }
                if (param4 > 2048)
                {
                    param4 = 2048;
                }
            }
            if (this._viewPort && this._viewPort.x == param1 && this._viewPort.y == param2 && this._viewPort.width == param3 && this._viewPort.height == param4 && this._antialias == param5)
            {
                return;
            }
            if (!this._viewPort)
            {
                this._viewPort = new Rectangle();
            }
            this._viewPort.x = param1;
            this._viewPort.y = param2;
            this._viewPort.width = param3;
            this._viewPort.height = param4;
            if (this._camera)
            {
                this._camera.updateProjectionMatrix();
            }
            if (this._stage3D && this.context)
            {
                this._stage3D.x = this._viewPort.x;
                this._stage3D.y = this._viewPort.y;
                this.context.configureBackBuffer(this._viewPort.width, this._viewPort.height, this._antialias, true);
            }
            Device3D.setViewPortRect(this._viewPort.width, this._viewPort.height, this.context);
            this.postProcess.resize(this._viewPort);
            this.textureOffsetX = (textureWidth - this._viewPort.width) * 0.5;
            this.textureOffsetY = (textureHeight - this._viewPort.height) * 0.5;
            FrEventDispatcher.instance.proxyDispatchEvent(this, Engine3dEventName.SCENE_VIEWPORT_CHANGE);
            return;
        }// end function

        public function get camera() : Camera3D
        {
            return this._camera;
        }// end function

        public function set camera(param1:Camera3D) : void
        {
            var _loc_2:* = this._camera;
            if (_loc_2)
            {
                _loc_2.parent = null;
            }
            this._camera = param1;
            var _loc_3:String = this;
            this._camera.parent = this;
            Global3D.camera = this.camera;
            if (_loc_2 != param1)
            {
                FrEventDispatcher.instance.proxyDispatchEvent(this, Engine3dEventName.CHANGE_CAMERA);
            }
            return;
        }// end function

        protected function enterFrameEvent(event:Event) : void
        {
            var _loc_2:int = 0;
            var _loc_3:TextureBase = null;
            var _loc_4:TextureBase = null;
            var _loc_5:int = 0;
            this._currTime = getTimer();
            if (this.context && this._updated)
            {
                this._updated = false;
                if (!this._paused)
                {
                    this.render(this._camera);
                    FrEventDispatcher.instance.proxyDispatchEvent(this, "postRender");
                    this.context.present();
                }
                else
                {
                    FrEventDispatcher.instance.proxyDispatchEvent(this, "render");
                }
            }
            Global3D.camera = this.camera;
            Device3D.cameraGlobal.copyFrom(this.camera.world);
            Device3D.setViewProj(this.camera.viewProjection, this.context);
            Device3D.proj.copyFrom(this.camera.projection);
            Device3D.view.copyFrom(this.camera.view);
            Global3D.scene = this;
            if (!this._paused)
            {
                Input3D.update();
                this.update();
            }
            else
            {
                FrEventDispatcher.instance.proxyDispatchEvent(this, "paused");
            }
            this._updated = true;
            return;
        }// end function

        override public function update(param1:int = 0) : void
        {
            var deepth:* = param1;
            var _t:* = getTimer();
            TimeControler.upDateTime(_t);
            if (TimeControler.stageFrame % 2 == 0 && this.context != null)
            {
                try
                {
                    Program3dManager.instance.checkToBuilderAndUpload();
                    Resource3dManager.instance.checkToParser(10);
                    Resource3dManager.instance.checkToUploadTexture(20);
                    Resource3dManager.instance.checkToUploadSurface(30, this.context);
                }
                catch (e:Error)
                {
                    Log.error("scene3d update error :" + e.message);
                }
            }
            super.update(deepth);
            return;
        }// end function

        public function set clipped(param1:Boolean) : void
        {
            this._clipped = param1;
            return;
        }// end function

        public function setupFrame(param1:Camera3D = null) : void
        {
            this.updateCameraPosVector();
            if (!param1)
            {
                param1 = this._camera;
            }
            Global3D.camera = param1;
            Device3D.cameraGlobal.copyFrom(param1.world);
            Device3D.setViewProj(param1.viewProjection, this.context);
            Device3D.proj.copyFrom(param1.projection);
            Device3D.view.copyFrom(param1.view);
            var _loc_2:* = param1.viewQuaternion;
            this._viewQuaternionTransform[1] = _loc_2;
            var _loc_3:* = Device3D.faceCameraQuaternion;
            _loc_3.x = _loc_2.x;
            _loc_3.y = _loc_2.y;
            _loc_3.z = _loc_2.z;
            _loc_3.w = _loc_2.w;
            Device3D.faceCameraMatrix3d.recompose(this._viewQuaternionTransform, Orientation3D.QUATERNION);
            Global3D.scene = this;
            param1.transform.copyColumnTo(2, Global3D.cameraForward);
            Global3D.cameraForward.normalize();
            var _loc_4:* = param1.clipRectangle;
            if (_loc_4)
            {
                this.context.setScissorRectangle(_loc_4);
                this._clipped = true;
            }
            else if (this._clipped)
            {
                this.context.setScissorRectangle(null);
                this._clipped = false;
            }
            return;
        }// end function

        override public function draw(param1:Boolean = true, param2:ShaderBase = null) : void
        {
            throw new Error("The Scene3D can not be drawn, please use render method instead.");
        }// end function

        public function resumData() : void
        {
            Global3D.trianglesDrawn = 0;
            Global3D.drawCalls3d = 0;
            Global3D.objectsDrawn = 0;
            return;
        }// end function

        public function render(param1:Camera3D = null, param2:Boolean = true) : void
        {
            if (!this.context)
            {
                return;
            }
            this.resumData();
            this._writeToTexture = this.postProcess.needRenderToTexture;
            if (this._writeToTexture)
            {
                this.renderToTexture(param1);
            }
            else
            {
                this.renderToScene(param1);
            }
            if (param2)
            {
                this.endFrame();
            }
            return;
        }// end function

        protected function renderToScene(param1:Camera3D) : void
        {
            if (param1.viewPort != this.viewPort)
            {
                param1.viewPort = this.viewPort;
            }
            param1.clipRectangle = null;
            this.setupFrame(param1);
            Device3D.setViewPortRect(this.viewPort.width, this.viewPort.height, this.context);
            this.context.setRenderToBackBuffer();
            this.context.clear(this.clearColor.x, this.clearColor.y, this.clearColor.z, this.clearColor.w, 1, 3);
            if (this.firstDrawFun != null)
            {
                this.firstDrawFun.apply();
            }
            if (this.context)
            {
                this.postProcess.renderShadow(this.context, this.renderLayerList);
                this.context.clear(0, 0, 0, 0, 1, 0, Context3DClearMask.STENCIL);
                this.postProcess.render(this.renderLayerList, this.context);
            }
            return;
        }// end function

        private function renderToTexture(param1:Camera3D) : void
        {
            if (param1.viewPort != this.staticRect)
            {
                param1.viewPort = this.staticRect;
            }
            param1.clipRectangle = this.postProcess.clipRect;
            this.setupFrame(param1);
            Device3D.setViewPortRect(this.staticRect.width, this.staticRect.height, this.context);
            this.context.setRenderToTexture(this.postProcess.firstBuffer.buffer, true, this._antialias);
            this.context.clear(this.clearColor.x, this.clearColor.y, this.clearColor.z, this.clearColor.w, 1, 3);
            if (this.firstDrawFun != null)
            {
                this.firstDrawFun.apply();
            }
            if (this.context)
            {
                this.postProcess.renderShadow(this.context, this.renderLayerList);
                this.context.clear(0, 0, 0, 0, 1, 0, Context3DClearMask.STENCIL);
                this.postProcess.render(this.renderLayerList, this.context);
                this.context.setStencilActions(Context3DTriangleFace.FRONT_AND_BACK, Context3DCompareMode.ALWAYS, Context3DStencilAction.KEEP);
                this.postProcess.doPostRendering(this.context);
            }
            return;
        }// end function

        public function endFrame() : void
        {
            var _loc_1:int = 0;
            _loc_1 = 0;
            var _loc_2:* = Global3D.usedSamples;
            var _loc_3:* = ShaderBase.textures;
            while (_loc_1 < _loc_2)
            {
                
                this.context.setTextureAt(_loc_1, null);
                _loc_3[_loc_1] = null;
                _loc_1++;
            }
            _loc_1 = 0;
            _loc_2 = Global3D.usedBuffers;
            while (_loc_1 < _loc_2)
            {
                
                this.context.setVertexBufferAt(_loc_1, null);
                ShaderBase.buffers[_loc_1] = null;
                _loc_1++;
            }
            Global3D.usedSamples = 0;
            Global3D.usedBuffers = 0;
            ShaderBase.pro = null;
            return;
        }// end function

        private function completeResourceEvent(event:Event) : void
        {
            if (this._camera.name != "Default_Scene_Camera")
            {
                return;
            }
            if (event.target == this._fist && event.target.hasOwnProperty("activeCamera") && event.target.activeCamera)
            {
                this.camera = event.target.activeCamera;
                this._camera.worldTransformChanged = true;
            }
            return;
        }// end function

        public function resume() : void
        {
            if (this._stage3D && this.context)
            {
                this.context.clear();
                this.render();
                this.context.present();
            }
            this.frameRate = this._frameRate;
            this._paused = false;
            return;
        }// end function

        public function pause() : void
        {
            this._paused = true;
            return;
        }// end function

        public function get paused() : Boolean
        {
            return this._paused;
        }// end function

        public function get antialias() : int
        {
            return this._antialias;
        }// end function

        public function set antialias(param1:int) : void
        {
            var anti:* = param1;
            if (this._antialias == anti)
            {
                return;
            }
            this._antialias = anti;
            if (this._viewPort && this._stage3D && this.context)
            {
                try
                {
                    this.context.configureBackBuffer(this._viewPort.width, this._viewPort.height, this._antialias, true);
                }
                catch (e:Error)
                {
                    Log.error("Scene3D set antialias error:" + e.message);
                }
            }
            return;
        }// end function

        public function get viewPort() : Rectangle
        {
            return this._viewPort;
        }// end function

        public function get frameRate() : Number
        {
            return this._frameRate;
        }// end function

        public function set frameRate(param1:Number) : void
        {
            this._frameRate = param1;
            this._startTime = getTimer();
            this._time = this._startTime;
            this._tick = 1000 / this._frameRate;
            return;
        }// end function

        public function get mouseEnabled() : Boolean
        {
            return this._mouseEnabled;
        }// end function

        public function set mouseEnabled(param1:Boolean) : void
        {
            this._mouseEnabled = param1;
            if (this._mouseEnabled == false)
            {
                this._last.mesh = null;
                this._info = null;
                this._down = null;
            }
            return;
        }// end function

        public function get enableUpdateAndRender() : Boolean
        {
            return this._enableUpdateAndRender;
        }// end function

        public function set enableUpdateAndRender(param1:Boolean) : void
        {
            this._enableUpdateAndRender = param1;
            if (param1 && this.context)
            {
                this._container.addEventListener(Event.ENTER_FRAME, this.enterFrameEvent, false, 0, true);
            }
            else
            {
                this._container.removeEventListener(Event.ENTER_FRAME, this.enterFrameEvent);
            }
            if (param1)
            {
                this.frameRate = this._frameRate;
            }
            return;
        }// end function

        public function set showMenu(param1:Boolean) : void
        {
            this._showMenu = param1;
            return;
        }// end function

        public function get stageIndex() : int
        {
            return this._stageIndex;
        }// end function

        public function get autoResize() : Boolean
        {
            return this._autoResize;
        }// end function

        public function set autoResize(param1:Boolean) : void
        {
            this._autoResize = param1;
            if (this.stage)
            {
                if (param1)
                {
                    this.stage.align = "tl";
                    this.stage.scaleMode = "noScale";
                    this.stage.addEventListener(Event.RESIZE, this.resizeStageEvent, false, 0, true);
                }
                else
                {
                    this.stage.removeEventListener(Event.RESIZE, this.resizeStageEvent);
                }
            }
            return;
        }// end function

        private function resizeStageEvent(event:Event) : void
        {
            this.setViewport(0, 0, this.stage.stageWidth, this.stage.stageHeight);
            return;
        }// end function

        public function get profile() : String
        {
            return this._profile;
        }// end function

        public function set profile(param1:String) : void
        {
            this._profile = param1;
            return;
        }// end function

        public function freeMemory() : void
        {
            var _loc_1:Surface3D = null;
            while (this.textures.length)
            {
                
                this.textures[0].download();
            }
            while (this.surfaces.length)
            {
                
                _loc_1 = this.surfaces[0];
                _loc_1.download();
            }
            return;
        }// end function

        public function registerClass(... args) : void
        {
            return;
        }// end function

        public function set sceneScale(param1:Number) : void
        {
            this._sceneScale = param1;
            this.camera.zoom = param1;
            return;
        }// end function

        public function get sceneScale() : Number
        {
            return this._sceneScale;
        }// end function

        public function updateCameraPosVector() : void
        {
            var _loc_1:* = Global3D.camera.pos;
            this.cpos[0] = _loc_1.x;
            this.cpos[1] = _loc_1.y;
            this.cpos[2] = _loc_1.z;
            this.cpos[3] = 1;
            return;
        }// end function

    }
}
